package com.jjwt.demo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.util.Date;

public class ParseJwtDemo2 {
    public static void main(String[] args) {
        String token="eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4ODg4IiwiaWF0IjoxNTczMTI4NDU0LCJzdWIiOiLlsI_mmI4iLCJleHAiOjE1NzMxMjg2MzMsInJvbGVzIjoiYWRtaW4iLCJsb2dvIjoibG9nby5wbmcifQ.WttNrX9EdxMbU_9W-LJ743q89RST4yAmhNG7qkG8D4Y";

        Claims claims = Jwts.parser().setSigningKey("zelin").parseClaimsJws(token).getBody();
        Object roles = claims.get("roles");
        Object login = claims.get("login");
        String id = claims.getId();
        Date issuedAt = claims.getIssuedAt();
        String subject = claims.getSubject();
        Date expiration = claims.getExpiration(); //过期时间
        System.out.println("login = " + login);
        System.out.println("expiration = " + expiration);
        System.out.println("roles = " + roles);
        System.out.println("id = " + id);
        System.out.println("issuedAt = " + issuedAt);
        System.out.println("subject = " + subject);
    }
}
